package org.feng.fxfront.client;

import org.feng.api.PageBean;
import org.feng.api.ResultVo;
import org.feng.api.animal.request.AddAndUpdateAnimalRequest;
import org.feng.api.animal.request.DeleteAnimalRequest;
import org.feng.api.animal.request.QueryAnimalRequest;
import org.feng.api.animal.response.AddAndUpdateAnimalDto;
import org.feng.api.animal.response.DeleteAnimalDto;
import org.feng.api.animal.response.QueryAnimalVo;
import org.feng.api.animal.service.AnimalApi;
import org.feng.fxfront.util.OkHttpUtil;

/**
 * 动物客户端
 *
 * @version v1.0
 * @author: fengjinsong
 * @date: 2024年01月25日 22时03分
 */
public class AnimalHttpClient implements AnimalApi {

    private static final String API_URL = "http://localhost:8080/fx-api";

    @Override
    public ResultVo<DeleteAnimalDto> deleteAnimal(DeleteAnimalRequest request) {
        final String shortUrl = "/api/animal/delete";
        String url = API_URL + shortUrl;
        return OkHttpUtil.post(url, request, DeleteAnimalDto.class);
    }

    @Override
    public ResultVo<AddAndUpdateAnimalDto> updateAnimal(AddAndUpdateAnimalRequest request) {
        final String shortUrl = "/api/animal/update";
        String url = API_URL + shortUrl;
        return OkHttpUtil.post(url, request, AddAndUpdateAnimalDto.class);
    }

    @Override
    public ResultVo<AddAndUpdateAnimalDto> addAnimal(AddAndUpdateAnimalRequest request) {
        final String shortUrl = "/api/animal/add";
        String url = API_URL + shortUrl;
        return OkHttpUtil.post(url, request, AddAndUpdateAnimalDto.class);
    }

    @Override
    public ResultVo<PageBean<QueryAnimalVo>> queryAnimal(QueryAnimalRequest request) {
        final String shortUrl = "/api/animal/query";
        String url = API_URL + shortUrl;
        return OkHttpUtil.postAndReturnPageBean(url, request, QueryAnimalVo.class);
    }
}
